package data;

import java.util.ArrayList;
import java.util.List;

public class Classifying {
	
	List<Data> data = new ArrayList<Data>();
	List<Data> pos = new ArrayList<Data>();
	List<Data> neg = new ArrayList<Data>();
	List<Data> neu = new ArrayList<Data>();
	
	public Classifying(List<Data> data, double[] ufactor, double[] ifactor, int k){
		for(int i=0; i<data.size(); i++){
			Data datum = data.get(i);
			int uid = datum.uid;
			short iid = datum.iid;
			byte rat = datum.rat;
			
			double dot = 0.0;
			
			for(int j=0; j<k; j++){
				dot += ufactor[k*(uid-1)+j]*ifactor[k*(iid-1)+j];
			}
			
			if(dot > 0){
				pos.add(datum);
				this.data.add(new Data(uid, iid, rat, (byte) 1));
			}
			else {
				neg.add(datum);
				this.data.add(new Data(uid, iid, rat, (byte) -1));
			}
		}
	}
	
	public Classifying(List<Data> data, double[] ufactor, double[] ifactor, int k, double epsilon) {
		for(int i=0; i<data.size(); i++){
			Data datum = data.get(i);
			int uid = datum.uid;
			short iid = datum.iid;
			byte rat = datum.rat;
			
			double dot = 0.0;
			
			for(int j=0; j<k; j++){
				dot += ufactor[k*(uid-1)+j]*ifactor[k*(iid-1)+j];
			}
			
			if(dot - epsilon > 0){
				pos.add(datum);
				this.data.add(new Data(uid, iid, rat, (byte) 1));
			}
			else if (dot + epsilon < 0){
				neg.add(datum);
				this.data.add(new Data(uid, iid, rat, (byte) -1));
			}
			else {
				neg.add(datum);
				this.data.add(new Data(uid, iid, rat, (byte) 0));
			}
		}
	}

	public List<Data> getData() {
		return data;
	}

	public List<Data> getPos() {
		return pos;
	}

	public List<Data> getNeg() {
		return neg;
	}

	public List<Data> getNeu() {
		return neu;
	}

}
